#ifndef SSHCHANNEL_H
#define SSHCHANNEL_H

#include <libssh/libssh.h>
#include <QDebug>

#include "QLibSsh_global.h"

class QLIBSSH_EXPORT SshChannel final : public SharePtr<ssh_channel>
{
public:
    explicit SshChannel(const ssh_channel& channel);

    ~SshChannel() override;

    [[nodiscard]] inline bool IsNull() const {
        return mPtr == nullptr;
    }

    [[nodiscard]] inline bool IsOpen() const {
        return ssh_channel_is_open(mPtr);
    }

    [[nodiscard]] inline bool IsEof() const {
        return ssh_channel_is_eof(mPtr);
    }

    [[nodiscard]] inline bool Open() const {
        return ssh_channel_open_session(mPtr) == SSH_OK;
    }

    inline void Close() const {
        ssh_channel_close(mPtr);
    }

    inline bool Exec(const char* command) const {
        return ssh_channel_request_exec(mPtr, command) == SSH_OK;
    }

    inline int Read(void* buffer, uint32_t length) const {
        return ssh_channel_read(mPtr, buffer, length, 0);
    }

    inline int Read(void* buffer, uint32_t length, int timeout) const {
        return ssh_channel_read_timeout(mPtr, buffer, length, 0, timeout);
    }

    inline int Write(void* buffer, uint32_t length) const {
        return ssh_channel_write(mPtr, buffer, length);
    }

    [[nodiscard]] bool RunInteractiveShell() const;

    [[nodiscard]] bool ChangeShellSize(int cols, int rows) const;

};

#endif // SSHCHANNEL_H
